﻿Chenxin.UI.ShowListLitigation = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListLitigation.ashx',
    createSearch: function() {
        return new Chenxin.UI.ShowListLitigationSearch({
            scope: this
        });
    },
    createGrid: function() {
        return new Chenxin.UI.JsonGrid({
            actionUrl: this.actionUrl + '?op=search',
            id: 'ListLitigation_table',
            renderTo: 'ListLitigation_table',
            hasCheckBox: false,
            cellBorder: true,
            pageSize: 50,
            height: 400,
            scope: this,
            modelId:'RecordId',
            columns: {
                RecordId: {
                    create: false,
                    head: 'id',
                    sortable: true
                },
                Status: {
                    head: '状态',
                    width: 110,
                    sortable: true,
                    renderer: function(val,c,row) {
                        var _v = '';
                        switch (val) {
                            case 0:
                                _v = '<span style="color:#aa0022">' + '诉讼申请，待审核' + '</span>';
                                break;
                            case -10:
                                _v = '<span style="color:#ff9900">' + '审核未通过，不予诉讼' + '</span>';
                                break;
                            case 10:
                                _v = '<span style="color:#006600">' + '审核通过予以诉讼' + '</span>';
                                break;
                            case 20:
                                _v = '<span style="color:#0033ff">' + '立案审理中' + '</span>';
                                break;
                            case 30:
                                _v = '<span style="color:#0088ff">' + '已裁决，执行中' + '</span>';
                                break;
                            case 40:
                                _v = '<span style="color:#">' + '已结案' + '</span>';
                                break;
                        }
                        return _v;
                    }
                },
                ContractCode: {
                    head: '成交编号',
                    width: 120,
                    sortable: true
                },
                HouseAddress: {
                    head: '地址',
                    width: 200,
                    sortable: true
                },
                AppDepart: {
                    head: '提交部门',
                    width: 80,
                    sortable: true
                },
                AppDate: {
                    head: '诉讼时间',
                    width: 71
                },
                LitigationMoney: {
                    head: '涉诉金额',
                    width: 70,
                    sortable: true
                },
                LitigationPerson: {
                    head: '诉讼对象',
                    width: 80,
                    sortable: true
                }
            }
        });
    },
    loadinfo: function() {
        var _this = this;
        if (!this.currentId) {
            alert("请先选择一条记录！");
            return false;
        }
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentInfo = data;
                }
            }
        });
        return true;
    },
    loadsubinfo: function() {
        var _this = this;
        if (!this.currentId) {
            alert("请先选择一条记录！");
            return false;
        }
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getsubmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentSubInfo = data;
                }
            }
        });
        return true;
    },
    loadAuditing: function() {
        var _this = this;
        if (!this.currentId) {
            alert("请先选择一条记录！");
            return false;
        }
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: this.actionUrl,
            data: { op: 'getAudmodel', modelid: this.currentId },
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentInfo = data;
                }
            }
        });
        return true;
    },
    initEvent: function() {
        var _this = this;
        /*************************事件：起始日期得到焦点************************/
        $("#DateFr").focus(function() {
            WdatePicker({ dateFmt: 'yyyy-MM-dd', oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        });
        /*************************事件：终止日期得到焦点************************/
        $("#DateTo").focus(function() {
            WdatePicker({ dateFmt: 'yyyy-MM-dd', oncleared: function() { $(this).blur(); }, onpicked: function() { $(this).blur(); } })
        });
        /*************************事件：诉讼申请************************/
        $("#aApplyLitigation").click(function() {
            _this.ApplyLitigation();
        });
        /*************************事件：诉讼审批************************/
        $("#aAuditing").click(function(){
            //诉讼审批
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条诉讼记录！");
                return;
            }
            _this.loadAuditing();
            if(_this.currentInfo.Status != 0)
            {
                alert("流程中未到或者已过诉讼审批阶段！");
            }
            else
            {
                _this.Auditing();
            }
        });
        /*************************事件：立案审理************************/
        $("#aCognizance").click(function(){
            //立案审理
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条诉讼记录！");
                return;
            }
            _this.loadsubinfo();
            if(_this.currentSubInfo.litigationInfo.Status != 10 && _this.currentSubInfo.litigationInfo.Status != 20)
            {
                alert("流程中未到或者已过立案审理阶段！");
            }
            else
            {
                _this.Cognizance();
            }
        });
        /*************************事件：裁决执行************************/
        $("#aVerdict").click(function(){
            //裁决执行
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条诉讼记录！");
                return;
            }
            _this.loadinfo();
            if(_this.currentInfo.Status != 20)
            {
                alert("流程中未到或者已过裁决执行阶段！");
            }
            else
            {
                _this.Verdict();
            }
        });
        /*************************事件：结案************************/
        $("#aCloseCase").click(function(){
            //结案
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条诉讼记录！");
                return;
            }
            _this.loadinfo();
            if(_this.currentInfo.Status != 30)
            {
                alert("流程中未到或者已过结案阶段！");
            }
            else
            {
                _this.CloseCase();
            }
        });
        /*************************事件：详情查看************************/
        $("#aShowDetial").click(function(){
            //详情查看复显示
            if (_this.currentId == null || _this.currentId == "" || _this.currentId == null) {
                alert("请先选择一条记录！");
                return;
            }
            Chenxin.Fn.checkPermit(_this.actionUrl,'showdetiallitigation',function(data,msg){
			    if(data.permit!=undefined){
				    _this.permit=data.permit;	
				    _this.msg = msg;
			    }
		    },this,{ modelid: _this.currentId });
		    if(_this.permit){			
                window.open("/page/Litigation_Mgr/ShowDetailLitagation.aspx?recordid="+_this.currentId+"");
		    }else{
			    alert(_this.msg);
		    }
        });
        /*************************事件：上传附件************************/
        $("#aUpload").click(function(){
            if (_this.currentId == null || _this.currentId == "" || _this.currentId == null) {
                alert("请先选择一条记录！");
                return;
            }
            
            if ($(this).attr("val")) {
                if (_this.currentId != $(this).attr("val")) {
                    _this.currentId = $(this).attr("val");
                    _this.loadinfo();
                }
            }
            _this.uploadAttachment();
        });
    },
    /**
    *诉讼申请
    */
    ApplyLitigation: function() {
        var _this = this;
        if (!this.ApplyLitigationForm) {
            this.ApplyLitigationForm = new Chenxin.UI.ApplyLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '诉讼申请',
                op: 'applylitigation',
                afterGetFormJson: function(json) {
                    if(json.ContractCode == undefined || json.ContractCode == "")
                    {
                        delete json.ContractCode;
                    }
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.ApplyLitigationForm.show()) {
            this.ApplyLitigationForm.reset();
        }
    },
    /**
    *诉讼审批
    */
    Auditing: function() {
        var _this = this;
        if (!this.AuditingLitigationForm) {
            this.AuditingLitigationForm = new Chenxin.UI.AuditingLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '诉讼审批',
                op: 'auditinglitigation',
                afterGetFormJson: function(json) {
                    delete json.ContractCode;
                    delete json.HouseAddress;
                    delete json.AppDepart;
                    delete json.AppDate;
                    delete json.LitigationMoney;
                    delete json.LitigationPerson;
                    if(json.AduRst == 10)
                    {
                        delete json.ApproveDepartId;
                        delete json.ApproveDepart;
                        delete json.ApproveEmployeeId;
                        delete json.ApproveEmployee;
                        delete json.ApproveReason;
                        delete json.Suggestion;
                    }
                    delete json.AduRst;
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.AuditingLitigationForm.show(this.AuditingLitigationForm.op, { currentId: _this.currentId })) {
            var _data = this.currentInfo;
			if(_data.ApproveEmployeeId=='00000000-0000-0000-0000-000000000000'){
				delete _data.ApproveEmployeeId;
			}
            this.AuditingLitigationForm.fitData(_data);
            this.AuditingLitigationForm.setTitle('诉讼审批');
        }
    },
    /**
    *立案审理
    */
    Cognizance: function() {
        var _this = this;
        if (!this.CognizanceLitigationForm) {
            this.CognizanceLitigationForm = new Chenxin.UI.CognizanceLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '立案审理',
                op: 'cognizancelitigation',
                afterGetFormJson: function(json) {
                    delete json.ContractCode;
                    delete json.HouseAddress;
                    if(json.CurrentTrialStatus == 10)
                    {
                        delete json.SecTrialDate;
                        delete json.SecTrialCourt;
                        delete json.SecTrialJudge;
                        delete json.SecTrialMemo;
                        delete json.LastTrialDate;
                        delete json.LastTrialCourt;
                        delete json.LastTrialJudge;
                        delete json.LastTrialMemo;
                        json.FirstTrialDate = json.TrialDate;
                        json.FirstTrialCourt = json.Court;
                        json.FirstTrialJudge = json.Judge;
                        json.FirstTrialMemo = json.TrialMemo;
                    }
                    else if(json.CurrentTrialStatus == 20)
                    {
                        delete json.FirstTrialDate;
                        delete json.FirstTrialCourt;
                        delete json.FirstTrialJudge;
                        delete json.FirstTrialMemo;
                        delete json.LastTrialDate;
                        delete json.LastTrialCourt;
                        delete json.LastTrialJudge;
                        delete json.LastTrialMemo;
                        json.SecTrialDate = json.TrialDate;
                        json.SecTrialCourt = json.Court;
                        json.SecTrialJudge = json.Judge;
                        json.SecTrialMemo = json.TrialMemo;
                    }
                    else if(json.CurrentTrialStatus == 30)
                    {
                        delete json.FirstTrialDate;
                        delete json.FirstTrialCourt;
                        delete json.FirstTrialJudge;
                        delete json.FirstTrialMemo;
                        delete json.SecTrialDate;
                        delete json.SecTrialCourt;
                        delete json.SecTrialJudge;
                        delete json.SecTrialMemo;
                        json.LastTrialDate = json.TrialDate;
                        json.LastTrialCourt = json.Court;
                        json.LastTrialJudge = json.Judge;
                        json.LastTrialMemo = json.TrialMemo;
                    }
                    delete json.TrialDate;
                    delete json.Court;
                    delete json.Judge;
                    delete json.TrialMemo;
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.CognizanceLitigationForm.show(this.CognizanceLitigationForm.op, { currentId: _this.currentId })) {
            var _data = this.currentInfo;
            var _subdata = this.currentSubInfo;
            this.CognizanceLitigationForm.fitData(_subdata.litigationSubInfo);
            if(_subdata.litigationSubInfo != undefined)
            {
                this.CognizanceLitigationForm.findByName('TrialDate').val(_subdata.litigationSubInfo.FirstTrialDate);
                this.CognizanceLitigationForm.findByName('Court').val(_subdata.litigationSubInfo.FirstTrialCourt);
                this.CognizanceLitigationForm.findByName('Judge').val(_subdata.litigationSubInfo.FirstTrialJudge);
                this.CognizanceLitigationForm.findByName('TrialMemo').val(_subdata.litigationSubInfo.FirstTrialMemo);
            }
            this.CognizanceLitigationForm.findByName('ContractCode').val(_subdata.litigationInfo.ContractCode);
            this.CognizanceLitigationForm.findByName('HouseAddress').val(_subdata.litigationInfo.HouseAddress);
            this.CognizanceLitigationForm.findByName('RecordId').val(_subdata.litigationInfo.RecordId);
            this.CognizanceLitigationForm.setTitle('立案审理');
        }
    },
    /**
    *裁决执行
    */
    Verdict: function() {
        var _this = this;
        if (!this.VerdictLitigationForm) {
            this.VerdictLitigationForm = new Chenxin.UI.VerdictLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '裁决执行',
                op: 'verdictlitigation',
                afterGetFormJson: function(json) {
                    delete json.ContractCode;
                    delete json.HouseAddress;
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.VerdictLitigationForm.show(this.VerdictLitigationForm.op, { currentId: _this.currentId })) {
            var _data = this.currentInfo;
            this.VerdictLitigationForm.fitData(_data);
            this.VerdictLitigationForm.setTitle('裁决执行');
        }
    },
    /**
    *结案
    */
    CloseCase: function() {
        var _this = this;
        if (!this.CloseCaseLitigationForm) {
            this.CloseCaseLitigationForm = new Chenxin.UI.CloseCaseLitigationForm({
                scope: _this,
                alwaysCheckPermit: true,
                title: '结案',
                op: 'closecaselitigation',
                afterGetFormJson: function(json) {
                    delete json.ContractCode;
                    delete json.HouseAddress;
                },
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.CloseCaseLitigationForm.show(this.CloseCaseLitigationForm.op, { currentId: _this.currentId })) {
            var _data = this.currentInfo;
            this.CloseCaseLitigationForm.fitData(_data);
            this.CloseCaseLitigationForm.setTitle('结案');
        }
    },
    /**
    *附件
    */
    uploadAttachment: function() {
        var _this = this;
        if (!this.UploadAttachForm) {
            this.UploadAttachForm = new Chenxin.UI.UploadAttachForm({
                scrop: this,
                title:'上传附件',
                op:'lituploadattach',
                saveSucc: function() {
                    _this.grid.reload();
                }
            });
        }
        if (this.UploadAttachForm.show(this.UploadAttachForm.op, { currentId: _this.currentId })) {
            this.UploadAttachForm.reset();
            this.UploadAttachForm.initUpload(this.currentId);
        }
        
    },
    initComponent: function() {
        Chenxin.UI.ShowListLitigation.superclass.initComponent.call(this);
    }
});

/**
*查询面板
*/
Chenxin.UI.ShowListLitigationSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
    id:'Litigation_search',
    initEvent:function(){
        var _this=this; 
        
        //查询按钮
        $('#btSreachLit').click(function(){
            _this.scope.searchGrid();
        });
		$('#Status').defText({
            deftxt: '请选择状态'
        });
        $('#HouseAddress').defText({
            deftxt: '输入物业地址'
        });
        $('#DateFr').defText({
            deftxt: '请选择下发时间'
        });
        $('#DateTo').defText({
            deftxt: '请选择下发时间'
        });
    },
    createComboList: function(){
        //状态
        var ComboStatus = new Chenxin.UI.Combo({
            containerId: '#Status',
            tbxWidth: 100,
            colWidth: 120,
            items: comboCommon.LitigationStatus
        });

        //五级联Combo
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(ComboStatus);
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.ShowListLitigationSearch.superclass.initComponent.call(this);
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(document).ready(function(){
    var showlistlitigation = new Chenxin.UI.ShowListLitigation();
});